

#include "stack.h"

void StackInit(stack* source,char* base, unsigned int baseSize,unsigned int number)
{
//	source = (stack*)malloc(sizeof(stack));
	source->bSize = baseSize;
	source->nSize = 0;
//	source->maxSize = baseSize*number;
	source->num = number;
	source->base = base;
	source->point = source->base;
}
void StackFree(stack* source)
{
	free(source->base);
}
void StackPush(stack* source,void* content)
{
	if(source->nSize >= source->num) return;
//	*(source->point) = *(content);
	char* buff = (char*) content;
	unsigned int i;
	for(i = 0 ; i < source->bSize ; i++)
	{
		*(source->point+i) = *(buff+i);		//problem
	}
	source->point += source->bSize;
	source->nSize++;
}
void StackPop(stack* source,void* target)
{
	if(source->nSize==0) return;
//	source->point = source->point - source->bSize;
//	*(target) = *(source->point);
//	char* buff = (char*) source->point;
	char* buff = (char*) target;
	source->point -=source->bSize;
	unsigned int i;
	for(i = 0 ; i < source->bSize ; i++)
	{
		*(source->point+i) = *(buff+i);		//problem
	}
	source->nSize--;
}
int StackEmpty(stack* source)
{
	if(source->nSize==0) return 1;
	return 0;
}
